<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="template.js"></script>
</head>

<body>
    <div id="user-box"></div>

    <script type="text/html" id="tpl-user">
      <div>姓名：{{name}}</div>
      <div>年龄：{{ age }}</div>
      <div>性别：{{  sex}}</div>
    </script>
    <script>
        //2.定义数据
        let obj = {
            name: 'ajax',
            age: 22,
            sex: '男'
        }

        // 3.调用模板函数
        let str = template('tpl-user', obj);

        // 4.数据渲染到页面
        document.querySelector('#user-box').innerHTML = str;
    </script>

</body>

</html>